﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Maxleaf.EDI.Domain;
using Maxleaf.EDI.Infrastructure.Exceptions;

namespace Maxleaf.EDI.DataAccess.UnitOfWork
{
    public class EFUnitOfWork : IUnitOfWork
    {
        public System.Data.Entity.DbContext Context { get; set; }

        public void Dispose()
        {
            if (null != this.Context)
            {
                this.Context.Dispose();
            }
        }

        public void Commit()
        {
            try
            {
                this.Context.SaveChanges();
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException e)
            {
                throw new UpdateAggregateRootException("Add or Update aggregate root failed.", e);
            }
        }
    }
}
